<?php

class MusicResultSet
{
	private $music = array();
	private $choir = "all";
	private $startDate;
	
	public function __construct($choir)
	{
		$this->choir=$choir;
		$this->startDate = new DateTime("2010-01-01 00:00:00");
	}
	
	public function setStartDate($date)
	{
		$this->startDate=$date;
	}
	
	public function getMusic()
	{
		$choirCondition="";
		if($this->choir=="clerks")$choirCondition="%L%";
		if($this->choir=="boys")$choirCondition="%[B]%";
		if($this->choir=="girls")$choirCondition="%[G]%";
		
		$database=$GLOBALS['DATABASE']->Recopy();
		$sql = "SELECT MusicListID FROM MusicAdmin_MusicList AS ml ";
		$sql .= "INNER JOIN Events as Ev on ml.SNAPEventID = Ev.EventID "; 
		$sql .= "INNER JOIN EventInvolvees AS Inv ON Ev.EventID = Inv.EventID ";

		$sql .= "WHERE Ev.Start > '".$this->startDate->format("Y-m-d")."' ";
		$sql .= "AND Ev.DeletedBy = 0 "; 
		$sql .= "AND ml.Deleted = 0 "; 
		$sql .= "AND Inv.EventInvolveeNameID = 14 "; // music required = 14
				
//		$sql .= " AND ml.Deleted = 0";
		
		if($choirCondition<>"")
			$sql .= "AND ml.Choir LIKE '".$choirCondition."' ";
		$sql .= "ORDER BY Ev.Start ";
		
//		echo $sql;

		$database->executeSQL($sql);
		while($row=$database->getRow())
		{
			$musicEvent=new MusicEvent($row['MusicListID']);
//			echo $row['MusicListID']."<br>\n";
			array_push($this->music,$musicEvent);
		}
		return $this->music;
	}
}
